package com.example.librarysystem.Controller;

import com.example.librarysystem.Service.UserinfoService;
import com.example.librarysystem.model.UserInfo;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserinfoService userinfoService;
    @RequestMapping("/login")
    public Boolean login(String username, String password, HttpSession session) {
        if(!StringUtils.hasLength(username) || !StringUtils.hasLength(password)) {
            return false;
        }
        UserInfo userInfo=userinfoService.queryUserinfobyname(username);
        if(userInfo==null) {
            return false;
        }
        if(password.equals(userInfo.getPassword())) {
            userInfo.setPassword("");
            session.setAttribute("session_user_info", userInfo);
            return true;
        }
        return false;
    }
}
